# -*- coding:utf-8 -*-
# @Time: 2020/8/24 17:43
# @Author: liupengfei
# @File: serializers.py

from rest_framework import serializers
from django.conf import settings
from utils.serializersfield import BooleanCheckCharField, ImageUploadCharField
from .models import Article


class RelateArticleSerialzier(serializers.ModelSerializer):
    '''关联文章列表'''
    key = serializers.SerializerMethodField()
    label = serializers.CharField(source='title')

    def get_key(self, obj):
        return obj.id

    class Meta:
        model = Article
        fields = ('key', 'label')


class ArticleSerializer(serializers.ModelSerializer):
    user = serializers.CharField(source='user.nickname', read_only=True)
    create_time = serializers.DateTimeField(format='%Y-%m-%d %H:%M', read_only=True)
    status_check = BooleanCheckCharField(source='status', read_only=True)
    is_top_check = BooleanCheckCharField(source='is_top', read_only=True)
    is_hot_check = BooleanCheckCharField(source='is_hot', read_only=True)
    is_recommend_check = BooleanCheckCharField(source='is_recommend', read_only=True)
    thumbnail_arr = ImageUploadCharField(source='thumbnail', read_only=True)

    '''后台管理创建'''

    class Meta:
        model = Article
        fields = '__all__'
